
unsigned int a[1024];
//unsigned int b[1024];
//unsigned int c[1024];
//unsigned int d[1024];

int fork();
void printi(unsigned int c);
void printc(char c);
void prints(const char *str);

int main(){
	unsigned int i = 5;
	prints("\nZacepin");
	prints(" is Megamozg!\n");
	for(i = 0;i < 128;i++){
		a[i] = i;
		printc((char) a[i]);
	}
	printi((unsigned int) a);
	a[1024] = 7;
	printi((unsigned int) &a[1024]);
	//for(;;);
	/*
	for(i = 0;i < 128;i++){
		b[i] = i;
		printc((char) b[i]);
	}
	
	for(i = 0;i < 128;i++){
		c[i] = i;
		printc((char) c[i]);
	}
	for(i = 0;i < 128;i++){
		d[i] = i;
		printc((char) d[i]);
	}
	*/
	a[10] = 0x11;
	prints("parent a[10] = ");
	printi(a[10]);
	printc('\n');

	int ret;
	asm("int $0x80":"=a" (ret):"a" (1));
	if(!ret){
		a[10] = 0xff;
		prints("child a[10] = ");
		printi(a[10]);
		printc('\n');
		for(;;);
	}
	
	prints("parent a[10] = ");
	printi(a[10]);
	printc('\n');
	a[10] = 0x77;
	//for(;;);
	int pid = fork();
	prints("PID: ");
	printi(pid);
	printc('\n');
	for(;;);
	if(!pid){
		prints("I am first child\n");
		a[1023] = 5;
		for(;;);
	}else{
		prints("Child started whith pid = ");
		printi(pid);
		printc('\n');
		pid = fork();
		if(!pid){
			prints("I am second child\n");
			for(;;);
		}else{
			prints("Child started whith pid = ");
			printi(pid);
			printc('\n');
			printi((unsigned int)a);
			a[1] = 5;
			a[1023] = 10;
			
			for(;;);
		}
		for(;;);
	}
	
	for(;;);
	return 0;
}

void _start(){
	main();
}

void printc(char c){
	
	asm("int $0x80"::"a" (0), "b" (c), "c" (0));
}

void printi(unsigned int c){
	asm("int $0x80"::"a" (0), "b" (c), "c" (1));
}


void prints(const char *str){
	while(*str != '\0'){
		printc(*str);
		str++;
	}
}

int fork(){
	int ret;
	asm("int $0x80":"=a" (ret):"a" (1));
	prints("FORK PID: ");
	printi(ret);
	printc('\n');
	return ret;
}

